#include <iostream>
#include<vector>
using namespace std;


int F(int l, int r, vector<int> ret1)
{
    int k = 0;
    for (int i = l; i <= r; i++)
    {
        k += ret1[i];
    }
    return k;
}

int G(int l, int r, vector<int> ret1)
{
    int k = 1;
    for (int i = l; i <= r; i++)
    {
        k |= ret1[i];
    }
    return k;
}
int H(int l, int r, vector<int> ret2)
{
    int k = 0;
    for (int i = l; i <= r; i++)
    {
        k ^= ret2[i];
    }
    return k;
}
int main()
{
    int n;
    cin >> n;
    vector<int> ret1(n + 1);
    vector<int> ret2(n + 1);
    for (int i = 1; i <= n; i++)
    {
        cin >> ret1[i];
    }

    for (int i = 1; i <= n; i++)
    {
        cin >> ret2[i];
    }

    int max = INT_MIN;
    for (int r = 1; r <= n; r++)
    {
        for (int l = 1; l <= r; l++)
        {
            int a = F(l, r, ret1);
            int b = G(l, r, ret1);
            int c = H(l, r, ret2);

            if (a - b == c)
            {
                if (r - l + 1 > max)
                {
                    max = r - l + 1;
                }
            }
        }
    }

    cout << max;
    return 0;
}


/*#include <iostream>
#include<vector>
#include<algorithm>
#include<numeric>
using namespace std;

int counttest(int mask)
{
    int count = 0;
    while (mask > 0)
    {
        if (mask & 1)
        {
            count++;
        }
        mask >>= 1;
    }
    return count;
}
int gcd(int a, int b)
{
    
    while (b != 0)
    {
        int tmp = b;
        b = a % b;
         a= tmp;
    }
    return a;
    
}
int countgcd(vector<int> ret)
{
    int k = ret[0];
    for (int num : ret)
    {
        k = gcd(k, num);
        if (k == 1)
        {
            break;
        }
    }

    return k;
}
int test(vector<int> ret, int k)
{
    int size = ret.size();
    int max = 0;
    for (int i = 0; i < (1 << size); i++)
    {
        if (counttest(i) != k)
        {
            continue;
        }

        vector<int> arr;
        for (int j = 0; j < size; j++)
        {
            if (!(i & (1 << j)))
            {
                arr.push_back(ret[j]);
            }
        }

        int g = countgcd(arr);

        if (g>max)
        {
            max = g;
        }
    }

    return max;
}
int main()
{
    int n, k;
    cin >> n >> k;
    vector<int> ret(n);
    for (int i = 0; i < n; i++)
    {
        cin >> ret[i];
    }

    int cur = test(ret, k);
    cout << cur;
    return 0;
}*/

/*#include <iostream>
#include<vector>
using namespace std;


int F(int l, int r, vector<int> ret1)
{
    int k = 0;
    for (int i = l; i <= r; i++)
    {
        k += ret1[i];
    }
    return k;
}

int G(int l, int r, vector<int> ret1)
{
    int k = 1;
    for (int i = l; i <= r; i++)
    {
        k |= ret1[i];
    }
    return k;
}
int H(int l, int r, vector<int> ret2)
{
    int k = 0;
    for (int i = l; i <= r; i++)
    {
        k ^= ret2[i];
    }
    return k;
}
int main()
{
    int n;
    cin >> n;
    vector<int> ret1(n + 1);
    vector<int> ret2(n + 1);
    for (int i = 1; i <= n; i++)
    {
        cin >> ret1[i];
    }

    for (int i = 1; i <= n; i++)
    {
        cin >> ret2[i];
    }

    int max = INT_MIN;
    for (int r = 1; r <= n; r++)
    {
        for (int l = 1; l <= r; l++)
        {
            int a = F(l, r, ret1);
            int b = G(l, r, ret1);
            int c = H(l, r, ret2);

            if (a - b == c)
            {
                if (r - l + 1 > max)
                {
                    max = r - l + 1;
                }
            }
        }
    }

    cout << max;
    return 0;
}*/



/*#include <iostream>
#include<string>
#include<vector>
using namespace std;

int count3(string s1, string s2)
{
    int num = 0;
    if (s1.empty())
    {
        return 0;
    }

    size_t len1 = s1.size();
    size_t len2 = s2.size();
    if (s1 > s2)
    {
        return 0;
    }

    size_t pos = s2.find(s1, 0);
    while (pos != string::npos)
    {
        num++;
        pos = s2.find(s1, pos + 1);
    }

    return num;

}
int count1(int p, int k, string s)
{
    string ret;
    for (int i = p - 1; i <= k - 1; i++)
    {
        ret += s[i];
    }

    int g = count3(ret, s);
    return g;
}

int count2(int p, int k, string s)
{
    string ret;
    for (int i = p - 1; i <= k - 1; i++)
    {
        ret += s[i];
    }

    int cur = 0;
    for (int i = 0; i < ret.size(); i++)
    {
        if (ret[i] == '1')
        {
            cur++;
        }
    }

    return cur;
}
int main()
{
    int n, q;
    cin >> n >> q;
    string s;
    cin >> s;

    vector<int> arr(q);
    arr.resize(q);

    for (int w = 0; w < q; w++)
    {
        int p, l, r;
        cin >> p >> l >> r;
        int k = 0;
        for (int i = l ; i <= r ; i++)
        {
            int a = count1(p, i, s);
            int b = count2(p, i, s);
            int c = a * b;
            k += c;
        }

        arr.push_back(k);

    }

   

    for (int i = 0; i < arr.size(); i++)
    {
        if (i != arr.size() - 1)
        {
            cout << arr[i] << endl;
        }
        else
        {
            cout << arr[i];
        }
    }

    return 0;
}*/